package com.arcbbs.utils;

import com.arcbbs.entity.ForumComment;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.util.DigestUtils;

public class StringTools {
    public static Boolean isEmpty(String str){
        if(null == str|| "".equals(str.trim()) || "null".equals(str)){
            return true;

        }else {
            return false;
        }
    }
    public static final String getFinalString(Integer count){
        return RandomStringUtils.random(count,true,true);

    }


    public static String getRandomNumber(Integer count) {
        return RandomStringUtils.random(count,false,true);

    }

    public static String md5(String password) {
        return StringTools.isEmpty(password)?null: DigestUtils.md5DigestAsHex(password.getBytes());
    }

    public static String getFileSuffix(String fileName) {
        System.out.println(fileName.substring(fileName.lastIndexOf("."))+"12334");
    return fileName.substring(fileName.lastIndexOf("."));
    }

    public static String eccapeHtml(String content) {
    if(StringTools.isEmpty(content)){
        return content;
    }
    content=content.replace("<","&lt;");
    content=content.replace(" ","&nbsp");
    content=content.replace("\n","<br>");
    return content;
    }

    public static String getFileName(String originalFilename) {
        return originalFilename.substring(0,originalFilename.lastIndexOf("."));

    }
}
